package com.letoken.platform.admin.controller;

import com.letoken.platform.admin.service.BlockchainService;
import com.letoken.platform.pub.annotation.auth.Permission;
import com.letoken.platform.pub.annotation.pub.Trim;
import com.letoken.platform.pub.req.PageData;
import com.letoken.platform.pub.req.QueryReqBase;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.admin.req.blockchain.AddBlockchainReq;
import com.letoken.platform.repo.admin.req.blockchain.DeleteBlockchainReq;
import com.letoken.platform.repo.admin.req.blockchain.UpdateBlockchainReq;
import com.letoken.platform.repo.admin.res.blockchain.QueryBlockchainListRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author letokenlabs
 * @date 2022/11/23$
 */
@RestController
@RequestMapping("/blockchain")
@Api(tags = "公链管理")
public class BlockchainController {

    @Autowired
    private BlockchainService blockchainService;


    @Permission(uri = "/blockchain/query/list",qx = "/blockchain/query/list")
    @Trim
    @PostMapping("/query/list")
    @ApiOperation(value = "公链列表", notes = "公链列表")
    public ApiResponse<PageData<QueryBlockchainListRes>> queryBlockchainList(@Validated @RequestBody QueryReqBase req) {
        return ApiResponse.create(blockchainService.queryBlockchainList(req));
    }

    @Permission(uri = "/blockchain/query",qx = "/blockchain/query")
    @Trim
    @PostMapping("/query/{id}")
    @ApiOperation(value = "查询单个公链", notes = "查询单个公链")
    public ApiResponse<QueryBlockchainListRes> queryBlockchainById(@PathVariable("id") Integer id) {
        return ApiResponse.create(blockchainService.queryBlockchainById(id));
    }

    @Permission(uri = "/blockchain/add",qx = "/blockchain/add")
    @Trim
    @PostMapping("/add")
    @ApiOperation(value = "添加公链", notes = "添加公链")
    public ApiResponse addBlockchain(@Validated @RequestBody AddBlockchainReq req) {
        blockchainService.addBlockchain(req);
        return ApiResponse.create();
    }

    @Permission(uri = "/blockchain/update",qx = "/blockchain/update")
    @Trim
    @PostMapping("/update")
    @ApiOperation(value = "编辑公链", notes = "编辑公链")
    public ApiResponse updateBlockchain(@Validated @RequestBody UpdateBlockchainReq req) {
        blockchainService.updateBlockchain(req);
        return ApiResponse.create();
    }

    @Permission(uri = "/blockchain/delete",qx = "/blockchain/delete")
    @Trim
    @PostMapping("/delete")
    @ApiOperation(value = "删除公链(包括批量)", notes = "删除公链(包括批量)")
    public ApiResponse deleteBlockchain(@Validated @RequestBody DeleteBlockchainReq req) {
        blockchainService.deleteBlockchain(req);
        return ApiResponse.create();
    }

    @Permission(uri = "/blockchain/uploadLogo",qx = "/blockchain/uploadLogo")
    @Trim
    @PostMapping("/uploadLogo")
    @ApiOperation(value = "上传公链logo", notes = "上传公链logo")
    public ApiResponse uploadLogo(@RequestPart("file") MultipartFile file) {
        return ApiResponse.create(blockchainService.uploadLogo(file));
    }


}
